package com.demos.diveinspring.service.impl;

import com.demos.diveinspring.service.CalculateService;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import java.util.stream.Stream;

/**
 * 条件装配注解 @Profile ： 主要当条件满足的时候才会加载装配这个bean
 * 这里的条件就是Java8
 */
@Profile("Java8")
@Service
public class Java8CalculateServiceImpl implements CalculateService {
    @Override
    public Integer sum(Integer... values) {
        System.out.println("Java 8 方式实现");
        int sum = Stream.of(values).reduce(0, Integer::sum);
        return sum;
    }
}
